const sampler_t sampler = CLK_ADDRESS_NONE | CLK_FILTER_NEAREST | CLK_NORMALIZED_COORDS_FALSE;

__kernel
void csr_opencl_img(__global float *values, __read_only image2d_t v, __global int *colIdx, __global int *rowPtr, const int rows, __global float *answer) {
	const int __idx = get_global_id(0);
	

	if(__idx >= rows)
		return;
	
	float accumulator = 0;
	int _row = __idx;

	for(int i = rowPtr[_row]; i < rowPtr[_row + 1]; i++) {
		int _col = colIdx[i];
		int coord = _col / 4;
		float4 temp = read_imagef(v, sampler, (int2)(0,coord));
		int imgPos = _col & 0x0003;
		float vecElement = 0;

		if (imgPos < 2) {
			if (imgPos == 0) vecElement = temp.x;
			else vecElement = temp.y;
		} else {
			if (imgPos == 2) vecElement = temp.z;
			else vecElement = temp.w;
		}
		accumulator += values[i] * vecElement;
	}

	answer[_row] = accumulator;
}